package com.market.quote.app.manager.marketManager;

import com.market.quote.modules.stock.domain.dto.StockInfoDTO;
import com.market.quote.modules.stock.domain.dto.StockRequestDTO;
import com.market.quote.modules.stock.domain.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author duweibin
 * @date 2024/4/22
 * @description com.market.quote.app.manager.queryManager
 */
@Service
@Slf4j
public class MarketManager {

    private final StockService stockService;

    @Autowired
    public MarketManager(StockService stockService) {
        this.stockService = stockService;
    }

    public List<StockInfoDTO> queryStockInfo(StockRequestDTO stockRequestDTO) {
        return stockService.getStockInfoList(stockRequestDTO);
    }

    public StockInfoDTO getStockInfoById(Long id) {
        return stockService.getStockInfoById(id);
    }

    public void saveStock(StockInfoDTO stockInfoDTO) {
        stockService.saveStock(stockInfoDTO);
    }


    @Async("registerSuccessExecutor")
    public void batchSaveStock(List<StockInfoDTO> stockInfoDTOList) {
        try{
            stockService.batchInsertStock(stockInfoDTOList);
            stockInfoDTOList.clear();
        } catch (Exception e) {
            log.error("批量添加失败，请处理，数据：{}", stockInfoDTOList,e);
        }

    }

    public void deleteStockById(Long id) {
        stockService.deleteStock(id);
    }
}
